<!--
 * @Author: xuzehan 123@qq.com
 * @Date: 2023-04-11 14:14:15
 * @LastEditors: xuzehan 935351619@qq.com
 * @LastEditTime: 2024-05-07 16:03:37
 * @FilePath: \ant-design-vue-jeecg-master\src\views\taskManagement\taskAllocation.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="taskAllocation">
    <a-collapse v-model="activeKey">
      <a-collapse-panel key="1" header="资源分配">
        <h2>
          上行频点切换
          <!-- <a-button @click="handleConfig" type="primary" style="margin-left: 10px">配置详情</a-button> -->
        </h2>
        <a-form-model
          :model="form1"
          :label-col="labelCol1"
          :wrapper-col="wrapperCol1"
          :rules="rulesForm"
        >
          <a-row>
            <a-col :span="8">
              <a-form-model-item label="指控车" prop="identificationCode">
                <a-select @change="changeCar" v-model="form1.identificationCode" placeholder="请选择">
                  <a-select-option
                    :value="item.identificationCode"
                    v-for="item in carlist"
                    :key="item.id"
                  >
                    {{
                    item.name
                    }}
                  </a-select-option>
                </a-select>
                <!-- <a-input v-model="form1.identificationCode" read-only></a-input> -->
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="导弹总数">
                <a-input read-only v-model="form1.applyMissileTotal"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="分配信道总数">
                <a-input v-model="form1.applyDigitalFilterTotal" read-only />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="8">
              <a-form-model-item label="受干扰导弹" prop="missileIdentificationCodes">
                <!-- <a-input v-model="form1.missileIdentificationCodes" /> -->
                <a-select
                  mode="multiple"
                  v-model="form1.missileIdentificationCodes"
                  placeholder="请选择"
                >
                  <a-select-option
                    v-for="item in ballList"
                    :key="item.id"
                    :value="item.identificationCode"
                  >
                    {{
                    item.identificationCode
                    }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="受干扰导弹总数" prop="interferencesNum">
                <a-input v-model="form1.interferencesNum" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="建议切换信道数" prop="switchNum">
                <a-input v-model="form1.switchNum" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="受干扰的信道" prop="disturbedDigitalFilters">
                <!-- <a-input v-model="form1.missileIdentificationCodes" /> -->
                <a-select mode="multiple" v-model="form1.disturbedDigitalFilters" placeholder="请选择">

                  <a-select-option v-for="(item,index) in pointList" :key="item" :value="item">
                    {{
                      item
                    }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <!-- <a-col :span="8">
              <a-form-model-item label="受干扰导弹" prop="missileIdentificationCodes">
                <a-select mode="multiple" v-model="form1.missileIdentificationCodes" placeholder="请选择">
                  <a-select-option
                    v-for="item in ballList"
                    :key="item.id"
                    :value="item.identificationCode"
                  >
                    {{
                    item.identificationCode
                    }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>-->
          </a-row>
          <a-card title="滤波器开关状态" style="width: 100%">
            <a-form-model
              ref="ruleFormZP"
              :label-col="labelCol1"
              :rules="rules"
              :wrapper-col="wrapperCol1"
              :model="formInline"
            >
              <a-row>
                <!-- <a-col :span="8">
                  <a-form-model-item label="L可控接收机" prop="LControllableReceiver">
                    <a-select v-model="formInline.LControllableReceiver">
                      <a-select-option :value="1">L可控接收机1</a-select-option>
                      <a-select-option :value="2">L可控接收机2</a-select-option>
                    </a-select>
                  </a-form-model-item>
                </a-col>-->
                <!-- <a-col :span="8">
                  <a-form-model-item label="本振编号" prop="localOscillator">
                    <a-select
                      default-value="0"
                      @change="changeLocalOscillator"
                      v-model="formInline.localOscillator"
                    >
                      <a-select-option
                        v-for="(item, index) in localOscillatorList"
                        :key="index"
                        :value="item.value"
                      >{{ item.label }}H</a-select-option>
                    </a-select>
                  </a-form-model-item>
                </a-col>-->
                <!-- <a-col :span="8">
                  <a-form-model-item label="中心频点" prop="cfp">
                    <a-input v-model="formInline.cfp" placeholder=" " read-only addon-after="MHz"></a-input>
                  </a-form-model-item>
                </a-col>-->
                <!-- <a-col :span="8">
                  <a-form-model-item :label-col="{ span: 3 }" :wrapper-col="{ span: 5 }">
                    <a-button
                      type="primary"
                      style="margin-left: 10px"
                      @click="handleSend('ZPLBQPZ')"
                    >发送</a-button>
                  </a-form-model-item>
                </a-col>-->
              </a-row>
              <a-row>
                <a-col :span="8">
                  <a-form-model-item label="中频滤波器">
                    <p style="line-height: 40px">
                      <span class="on">开</span>
                      <span class="off">关</span>
                      <span class="dis">禁用</span>
                    </p>
                  </a-form-model-item>
                </a-col>
                <a-col :span="24">
                  <div class="ZPLBQList">
                    <div v-for="item in ZPLBQList" :key="item.id" class="ZPLBQBox">
                      <a-popover title="详情" v-if="!item.disabled">
                        <div
                          @click="changeCheckS(item)"
                          :class="!item.disabled ? (item.check ? 'oncheck' : 'offcheck') : 'disabledStyle'"
                        >{{ item.label }}</div>
                        <template slot="content">
                          <p>中频滤波器编号：{{ item.no }}</p>
                          <p>中频滤波器带宽：{{ item.DK }}MHz</p>
                          <p>中频滤波器中心频点：{{ item.ZXPD }}</p>
                        </template>
                      </a-popover>
                      <div
                        v-else
                        @click="changeCheckS(item)"
                        :class="!item.disabled ? (item.check ? 'oncheck' : 'offcheck') : 'disabledStyle'"
                      >{{ item.label }}</div>
                    </div>
                  </div>
                </a-col>
              </a-row>
            </a-form-model>
            <a-form-model v-bind="layout" :model="formInline" style="margin-top: 30px">
              <a-row>
                <a-col :span="24">
                  <a-form-model-item
                    label="数字滤波器"
                    :label-col="{ span: 3 }"
                    :wrapper-col="{ span: 18 }"
                  >
                    <div style="line-height: 40px; color: #fff; display: flex; align-items: start">
                      <span class="on">开</span>
                      <span class="off">关</span>
                      <span class="dis">禁用</span>
                      <div style="display: flex; margin-left: 30px">
                        <p style>注意:数字滤波器配置尽量满足相邻的信道不同时处于“开”的状态</p>
                      </div>
                      <!-- <a-button
                        type="primary"
                        style="margin-left: 50px"
                        @click="handleSend('SZLBQPZ')"
                      >发送</a-button>-->
                    </div>
                  </a-form-model-item>
                </a-col>
                <a-col :span="24">
                  <div class="SZLBQList">
                    <div v-for="item in SZLBQList" :key="item.id" class="SZLBQBox">
                      <a-popover title="详情" v-if="!item.disabled">
                        <div
                          @click="changeCheckSZLPQ(item.id)"
                          :class="!item.disabled ? (item.check ? 'oncheck' : 'offcheck') : 'disabledStyle'"
                        >{{ item.label }}</div>
                        <template slot="content">
                          <p>数字滤波器编号：{{ item.id }}</p>
                          <p>数字滤波器带宽：375kHz</p>
                          <p>数字滤波器中心频点：{{ formatF(item.id) }}</p>
                        </template>
                      </a-popover>
                      <div
                        v-else
                        @click="changeCheckSZLPQ(item.id)"
                        :class="!item.disabled ? (item.check ? 'oncheck' : 'offcheck') : 'disabledStyle'"
                      >{{ item.label }}</div>
                    </div>
                  </div>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24" :style="{ textAlign: 'right', marginRight: '30px' }">
                    <a-popconfirm style="margin-left: 10px"  overlayClassName="poperLayTable"   title="确定发送指令吗?" @confirm="() => handleSend()" >
                        <a-button type="primary">发送</a-button>
                      </a-popconfirm>
                  <!-- <a-button type="primary" style="margin-left: 10px" @click="handleSend">发送</a-button> -->
                </a-col>
              </a-row>
            </a-form-model>
          </a-card>
          <!-- <a-card title="数字滤波器开关状态" style="width: 100%">
            <a-form-model v-bind="layout" :model="formInline">
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="数字滤波器" :label-col="{ span: 3 }" :wrapper-col="{ span: 18 }">
                    <div style="line-height: 40px; color: #fff; display: flex; align-items: start">
                      <span class="on">开</span>
                      <span class="off">关</span>
                      <span class="dis">禁用</span>
                      <div style="display: flex; margin-left: 30px">
                        <p style="">注意:</p>
                        <p style="line-height: 20px; margin: 0">
                          1.数字滤波器配置尽量满足相邻的信道不同时处于“开”的状态<br />2.每次开启的数字滤波器个数固定为32个
                        </p>
                      </div>
                      <a-button type="primary" style="margin-left: 50px" @click="handleSend('SZLBQPZ')"> 发送</a-button>
                    </div>
                  </a-form-model-item></a-col
                >
                <a-col :span="24">
                  <div class="SZLBQList">
                    <div v-for="item in SZLBQList" :key="item.id" class="SZLBQBox">
                      <a-popover title="详情" v-if="!item.disabled">
                        <div
                          @click="changeCheckSZLPQ(item.id)"
                          :class="!item.disabled ? (item.check ? 'oncheck' : 'offcheck') : 'disabledStyle'"
                        >
                          {{ item.label }}
                        </div>
                        <template slot="content">
                          <p>数字滤波器编号：{{ item.id }}</p>
                          <p>数字滤波器带宽：375kHz</p>
                          <p>数字滤波器中心频点：{{ formatF(item.id) }}</p>
                        </template>
                      </a-popover>
                      <div
                        v-else
                        @click="changeCheckSZLPQ(item.id)"
                        :class="!item.disabled ? (item.check ? 'oncheck' : 'offcheck') : 'disabledStyle'"
                      >
                        {{ item.label }}
                      </div>
                    </div>
                  </div>
                </a-col>
              </a-row>
            </a-form-model>
          </a-card>-->
        </a-form-model>
      </a-collapse-panel>
      <!-- <a-collapse-panel key="2" header="控制指令发送及响应"></a-collapse-panel> -->
    </a-collapse>
    <creat-instruct ref="creatInstruct" />
    <configModal ref="configModal" />
    <a-modal :visible="visible" width="55%" title="资源分配申请表" @cancel="handleOk" @ok="handleOk">
      <template slot="footer">
        <a-button key="submit" type="primary" @click="handleOk">退出</a-button>
      </template>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columnsSQB"
        :dataSource="dataSourceSQB"
        :pagination="ipagination"
        class="j-table-force-nowrap"
      >
        <span slot="action" slot-scope="text, record">
          <a-button @click="handleOk1(record)" type="primary">进入配置</a-button>
        </span>
      </a-table>
    </a-modal>
    <a-modal
      title
      :visible="visibleConfirm"
      @ok="handleOkConfirm"
      @cancel="handleCancelConfirm"
    >确认是否切换以下导弹上行链路频点号 ? {导弹1 2 3}</a-modal>
  </div>
</template>

<script>
import { processDefineKey } from '@/api/processDefineKey'
import CascaderSelect from './modules/Cascader.vue'
import creatInstruct from './modules/createInstruct'
import { getAction, httpAction } from '@/api/manage.js'
import configModal from './modules/confidModal.vue'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
//  <!-- 资源池 -->
import pool1 from './modules/resourcePool1.vue'
import { Turns, sum, hex2int } from '@/utils/util.js'
import { Select } from 'ant-design-vue'
export default {
  mixins: [JeecgListMixin],
  components: { creatInstruct, pool1, CascaderSelect, configModal },
  data() {
    return {
      data: {},
      carlist: [],
      selectZPList: [],
      ballList: [],
      visibleConfirm: false,
      visible: false,
      readOnly: false,
      columnsSQB: [
        {
          title: '指挥车名称',
          dataIndex: 'identificationCode',
          key: 'identificationCode',
        },
        {
          title: '导弹总数',
          dataIndex: 'applyMissileTotal',
          key: 'applyMissileTotal',
        },
        {
          title: '信道号总数（个）',
          dataIndex: 'applyDigitalFilterTotal',
          key: 'applyDigitalFilterTotal',
        },
        {
          title: '操作',
          key: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      layout: {
        labelCol: { span: 4 },
        wrapperCol: { span: 14 },
      },
      formInline: { localOscillator: '', cfp: '' },
      dataSourceSQB: [],
      text: `world.`,
      value1: 'a',
      value2: '1',
      value3: 'a',
      poolData: [],
      tabActiveKey: '1',
      activeKey: ['1', '2'],
      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
      labelCol1: { span: 8 },
      wrapperCol1: { span: 16 },
      form: {},
      fightForm: { startDate: undefined },
      form1: { disturbedDigitalFilters:undefined,applyMissileTotal: undefined, applyDigitalFilterTotal: undefined },
      formUp: { Values: [], packageGridValue: '' },
      formBall: {},
      resourcesForm: {},
      resourcesList: [],
      resourcesNo: {},
      check: [],
      checkList: [],
      resourcesList: [],
      props: { multiple: true },
      ac: [
        { active: 1, disabled: [] },
        { active: 2, disabled: [] },
        { active: 3, disabled: [] },
        { active: 4, disabled: [] },
      ],
      das: null,
      multipleTreeData: [],
      url: {
        getCarList: '/commandVehicle/nmcCommandVehicle/getByCurrentDayOfCommandVehicleExcludeRetired',
        getBallList: '/missile/nmcMissileInfo/getByNcvIdentificationCode',
        getControllableReceiverInfo: '/telemetryInfo/nmcTelemetryInfo/getControllableReceiverInfo',
        getIntermediateFrequencyFilterInfo: '/telemetryInfo/nmcTelemetryInfo/getIntermediateFrequencyFilterInfo',
        getLocalOscillatorInfo: '/telemetryInfo/nmcTelemetryInfo/getLocalOscillatorInfo',
        getByCurrentDayOfCommandVehicleExcludeRetired:
          '/commandVehicle/nmcCommandVehicle/getByCurrentDayOfCommandVehicleExcludeRetired',
          getDigitalFilterInfo:'/telemetryInfo/nmcTelemetryInfo/getDigitalFilterInfo',
        uplinkFrequencySwitchDecision: '/upAntiInterference/nmcUpAntiInterference/uplinkFrequencySwitchDecision',
        // addnmcPackageGridValue: '/grid/nmcPackageGridValue/add', //{"packageGridValue":"22AA","Values":["22","aa"],"packageGridId":"1663806762680139777"}
      },
      localOscillatorList: [
        { label: '0', value: '0', cfp: '5540' },
        { label: '1', value: '1', cfp: '5560' },
        { label: '2', value: '2', cfp: '5580' },
        { label: '3', value: '3', cfp: '5600' },
        { label: '4', value: '4', cfp: '5620' },
        { label: '5', value: '5', cfp: '5640' },
        { label: '6', value: '6', cfp: '5660' },
        { label: '7', value: '7', cfp: '5680' },
        { label: '8', value: '8', cfp: '5700' },
        { label: '9', value: '9', cfp: '5720' },
        { label: '10', value: 'A', cfp: '5740' },
        { label: '11', value: 'B', cfp: '5760' },
        { label: '12', value: 'C', cfp: '5780' },
        { label: '13', value: 'D', cfp: '5800' },
        { label: '14', value: 'E', cfp: '5820' },
      ],
      ZPLBQList: [
        {
          id: 0,
          label: '中频滤波器0',
          no: '00H',
          DK: '6',
          ZXPD: '939MHz',
          check: false,
          disabled: false,
          sz: [114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125],
        },
        {
          id: 1,
          label: '中频滤波器1',
          no: '01H',
          DK: '6',
          ZXPD: '944.25MHz',
          check: false,
          disabled: false,
          sz: [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111],
        },
        {
          id: 2,
          label: '中频滤波器2',
          no: '02H',
          DK: '6',
          ZXPD: '949.5MHz',
          check: false,
          disabled: false,
          sz: [86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97],
        },
        {
          id: 3,
          label: '中频滤波器3',
          no: '03H',
          DK: '6',
          ZXPD: '954.75MHz',
          check: false,
          disabled: false,
          sz: [72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83],
        },
        {
          id: 4,
          label: '中频滤波器4',
          no: '04H',
          DK: '6',
          ZXPD: '960MHz',
          check: false,
          disabled: false,
          sz: [58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69],
        },
        {
          id: 5,
          label: '中频滤波器5',
          no: '05H',
          DK: '6',
          ZXPD: '965.25MHz',
          check: false,
          disabled: false,
          sz: [44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55],
        },
        {
          id: 6,
          label: '中频滤波器6',
          no: '06H',
          DK: '6',
          ZXPD: '970.5MHz',
          check: false,
          disabled: false,
          sz: [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41],
        },
        {
          id: 7,
          label: '中频滤波器7',
          no: '07H',
          DK: '6',
          ZXPD: '975.75MHz',
          check: false,
          disabled: false,
          sz: [
            // 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
            27,
          ],
        },
        {
          id: 8,
          label: '中频滤波器8',
          no: '08H',
          DK: '6',
          ZXPD: '981MHz',
          check: false,
          disabled: false,
          sz: [],
          // sz: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
        },
        {
          id: 9,
          label: '中频滤波器9',
          no: '09H',
          DK: '20MHz',
          ZXPD: '960MHz',
          check: false,
          disabled: false,
          sz: [
            38, 39, 40, 41, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,
            69, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 86, 87, 88, 89,
          ],
        },
      ],
      SZLBQList: [],
      pointList:[],
      rules: {
        localOscillator: [{ required: true, message: '请选择', trigger: 'change,blur' }],
        cfp: [{ required: false, message: '请选择', trigger: 'change' }],
      },
      rulesForm: {
        interferencesNum: [
          { required: true, message: '请输入', trigger: 'change' },
          { validator: this.validateInterferencesNum },
        ],
        disturbedDigitalFilters: [{ required: true, message: '请输入', trigger: 'change' },],
        switchNum: [{ required: true, message: '请输入', trigger: 'change' },],
        missileIdentificationCodes: [{ required: true, message: '请输入', trigger: 'change' },],
        identificationCode: [{ required: true, message: '请输入', trigger: 'change' },],
        switchNum: [{ required: true, message: '请输入', trigger: 'change' }, { validator: this.validateSwitchNum }],
      },
    }
  },
  watch: {
    activeKey(key) {
      console.log(key)
    },
  },
  active() {
    this.loadData()
  },
  created() {
    this.initBox()
    // this.initBox() //生成128个数字滤波器
    // this.loadData()
    // this.getModalList()//获取要要配置的列表数据
  },
  methods: {
    changeCar(val) {
      this.form1.disturbedDigitalFilters=[]
      let arr=this.carlist.find(i => i.identificationCode == val).digitalFilterPreAllocInfo

      this.pointList=arr.split(',')
      this.form1.applyMissileTotal = this.carlist.find(i => i.identificationCode == val).planApplyMissileTotal
      this.form1.applyDigitalFilterTotal = this.carlist.find(i => i.identificationCode == val).missileUpChannelsNumber
      getAction(this.url.getBallList, { ncvIdentificationCode: val }).then((res) => {
        this.ballList = res.result
      })

    },
    validateSwitchNum(rule, value, callback) {
      if (value > this.form1.applyDigitalFilterTotal) {
        callback('建议切换信道数不能大于总信道数！')
      } else {
        callback()
      }
    },
    validateInterferencesNum(rule, value, callback) {
      if (value > this.form1.applyMissileTotal) {
        callback('受干扰导弹总数不能大于导弹总数！')
      } else {
        callback()
      }
    },
    getModalList() {
      getAction(this.url.getModalList, { pageSize: -1 }).then((res) => {
        if (res.success) {
          if (res.result.records && res.result.records.length) {
            this.dataSourceSQB = res.result.records
          } else {
            this.dataSourceSQB = []
          }
        } else {
          this.$message.error(res.message)
        }
      })
    },
    formatF(n) {
      let m = Number(this.formInline.localOscillator)
      return 1660.1875 + m * 20 + Number(n) * 0.375
    },
    setBzValue(bz) {
      this.formInline.localOscillator = bz.slice(-1) //已配置的本振赋值
      this.changeLocalOscillator(bz.slice(-1)) //中心频点赋值
    },
    setZpValue(zp) {
      let b = zp //已配置的中频滤波器
      let results = Turns(b, 2).slice(0, -2).split('').reverse()
      results.forEach((i, index) => {
        if (i == 1) {
          this.changeCheckS(
            this.ZPLBQList.find((item, idx) => idx == index),
            1
          )
        }
      })
    },
    setSzValue(sz, result) {
      // this.formInline.sz = result.frequencyFilterOpenInfo.packageGridValue//32个数字滤波器
      let select = [] //已选择的数字滤波器十进制编号
      result.nmcCommandVehicleVoList.forEach((i) => {
        select.push(i.digitalFilterList)

        // this.SZLBQList.find((item, idx) => idx == index) = Object.assign(this.SZLBQList.find((item, idx) => idx == index), i)
      })
      let selectArr = select.flat()
      let result1 = this.Turns(sz, 2).split('').reverse()
      this.SZLBQList.forEach((i) => {
        i.check = false
      })
      result1.forEach((i, index) => {
        if (i == 1) {
          if (selectArr.indexOf(String(index)) != -1) {
            this.SZLBQList.find((item, idx) => idx == index).disabled = true
            this.SZLBQList.find((item, idx) => idx == index).check = false
          }
        }
      })
    },
    // getLatestPackageGridValue() {
    //   const that = this
    //   let obj = {
    //     gridCode: '2-可控接收机本振频点切换指令',
    //     packageCode: '2星弹上行链路接收机频率配置1',
    //     processDefineKey: processDefineKey.SatelliteBombUpReceiverFreConfOneHandleImplKey,
    //   }
    //   getAction(this.url.getLatestPackageGridValue, obj).then((res) => {
    //     let a = res.result.packageGridValue
    //     this.formInline.localOscillator = a.slice(-1)
    //     this.changeLocalOscillator(a.slice(-1))
    //   })
    //   let obj1 = {
    //     gridCode: '2-滤波器选通指令',
    //     packageCode: '2星弹上行链路接收机频率配置1',
    //     processDefineKey: processDefineKey.SatelliteBombUpReceiverFreConfOneHandleImplKey,
    //   }
    //   getAction(this.url.getLatestPackageGridValue, obj1).then((res) => {
    //     let b = res.result.packageGridValue
    //     let result = Turns(b, 2).slice(0, -2).split('').reverse()
    //     result.forEach((i, index) => {
    //       if (i == 1) {
    //         this.changeCheckS(
    //           that.ZPLBQList.find((item, idx) => idx == index),
    //           1
    //         )
    //       }
    //     })
    //   })

    //   let obj2 = {
    //     gridCode: '3-滤波器选通指令',
    //     packageCode: '3星弹上行链路接收机频率配置2',
    //     processDefineKey: processDefineKey.SatelliteBombUpReceiverFreConfTwoHandleImplKey,
    //   }
    //   getAction(this.url.getLatestPackageGridValue, obj2).then((res) => {
    //     let a = res.result.packageGridValue
    //     let result = this.Turns(a, 2).split('').reverse()
    //     that.SZLBQList.forEach((i) => {
    //       i.check = false
    //     })
    //     result.forEach((i, index) => {
    //       if (i == 1) {
    //         that.SZLBQList.find((item, idx) => idx == index).check = true
    //         // this.changeCheckSZLPQ(that.SZLBQList.find((item, idx) => idx == index).id)
    //       }
    //     })
    //   })
    // },
    initBox() {
      this.SZLBQList = []
      for (let i = 0; i < 128; i++) {
        let obj = { id: i, disabled: true, check: false, label: i }
        this.SZLBQList.push(obj)
      }
    },

    loadData() {
      let unSelect
      let that=this
      getAction(this.url.getIntermediateFrequencyFilterInfo).then((res) => {
        //中频滤波器=[0,1,2]
        this.selectZPList = res.result
        res.result.forEach((i) => {
          this.changeCheckTrue(this.ZPLBQList.find((item) => item.id == i))
        })
      })
      getAction(this.url.getDigitalFilterInfo).then(res1=>{
        if(res1.success){
          let all=res1.result
          getAction(this.url.getCarList).then((res) => {
            this.carlist = res.result
            let temp = []
            this.carlist.forEach(i => {
              temp.push(i.digitalFilterPreAllocInfo.split(','))
            })
            unSelect = temp.flat()
            let arr=[]
                all.forEach(i=>{
                  // console.log(unSelect.indexOf(String(i)));
                  if(unSelect.indexOf(String(i))==-1){
                    arr.push(i)
                  }
                })

              arr.forEach(item => {
                // console.log(that.SZLBQList.find(i => i.id == item),item,'item');
                that.SZLBQList.find(i => i.id == item).disabled = false
                that.SZLBQList.find(i => i.id == item).check = false
            })
          })

        }else{

          this.$message.error(res.message)
        }
      })


      // getAction(this.url.getLocalOscillatorInfo).then(res => {
      //   // console.log(res)
      //   this.formInline.localOscillator = String(res.result)
      //   this.changeLocalOscillator(res.result)
      // })

      // getAction(this.url.getControllableReceiverInfo).then(res => {
      //   this.formInline.LControllableReceiver = res.result
      // })
      // //获取今天所有的指挥车信息排除已退网的
      // getAction(this.url.getByCurrentDayOfCommandVehicleExcludeRetired).then(res => {
      //   console.log(res, 'ressss----')
      // })
    },
    changeCheckTrue(item, type) {
      this.$nextTick(() => {
        this.ZPLBQList.forEach((i) => {
          if (i.id == item.id) {
            i.check = true
          }
        })
        // let select = this.ZPLBQList.find((i) => i.id == item.id)
        // item.sz.forEach((j) => {
        //   this.SZLBQList.find((x) => x.id == j).disabled = false
        // })

      })
    },
    changeCheckSZLPQ(id) {
      let select = this.SZLBQList.find((i) => i.id == id)
      if (select.disabled) return
      select.check = !select.check
    },
    changeCheck(item) {
      // console.log(item, 'item')
    },
    changeCheckS(item, type) {
      //点击中频滤波器
      if (this.selectZPList.indexOf(item.id) != -1) return  //原本选中的中频滤波器不可以关掉
      if (this.readOnly && !type) return //如果readOnly了 取消点击事件
      let id = item.id
      let select = this.ZPLBQList.find((i) => i.id == id)
      item.sz.forEach((j) => {
        // console.log(j, this.SZLBQList.find((x) => x.id == j).disabled, !i.check)
        this.SZLBQList.find((x) => x.id == j).disabled = select.check
      })

      if (select.disabled) return
      select.check = !select.check
      let arr = ['02H', '03H', '04H', '05H', '06H']
      let selectArr = [] //所有选中的no
      // this.SZLBQList = []
      this.ZPLBQList.forEach((i, index) => {
        if (i.check) {
          selectArr.push(i.no)
        }
        select.no == '09H' && arr.forEach((item) => i.no == item && (i.disabled = select.check))
      })
      //选中 2.3.4.5.6 中的一个
      let newArr = new Set(arr)
      let newselectArr = new Set(selectArr)
      let res = Array.from(new Set([...newArr].filter((x) => newselectArr.has(x)))) //获取两个set集合的交集用array.from返回
      this.ZPLBQList.find((i) => i.no == '09H').disabled = !!res.length
      // ------
    },
    changeLocalOscillator(val) {
      this.formInline.cfp = this.localOscillatorList.find((i) => i.value == val).cfp //本振编号联动中心频点

      this.ZPLBQList.forEach((item) => {
        item.check = false
      })
      this.SZLBQList.forEach((item) => {
        item.disabled = true
        item.check = false
      })
      //请求查询该本振下的中频滤波器和数字滤波器的打开状态
    },
    handleOkConfirm() {
      httpAction(this.url.sendConfig, this.data, 'post').then((res) => {
        if (res.code == 200) {
          that.$message.success('发包成功！')
          this.visible = true
          this.visibleConfirm = false
          this.getModalList()
        } else {
          that.$message.error('发包失败！')
        }
      })
    },
    handleCancelConfirm() {
      this.visibleConfirm = false
    },
    handleOk() {
      this.$router.back()
    },
    handleOk1(record) {
      this.visible = false
      this.form1 = record ? record : {}
      // this.getLatestPackageGridValue()//获取最新值
      getAction(this.url.queryInfo).then((res) => {
        let result = res.result
        if (result.nmcCommandVehicleVoList.length > 0) {
          //有指控车配置过中频滤波器和本振（则不可修改）中频滤波器和本振
          this.readOnly = true
          this.setBzValue(result.localFrequencyPoint.packageGridValue)
          this.setZpValue(result.intermediateFrequencyFilter.packageGridValue)
          this.setSzValue(result.frequencyFilterOpenInfo.packageGridValue, result)
          return
        } else {
          this.readOnly = false
        }
      })
      // record.configured = true
      // if (record.configured) {

      //   this.readOnly = true //不可修改
      //   //如果已经配置过了configured为true，中频滤波器与本振编号已有且不可修改，数组滤波器的可选项固定
      //   let zplbqValue = [2, 3, 4]//中频滤波器的数值
      //   let selectZP = []
      //   zplbqValue.forEach(item => {
      //     if (this.ZPLBQList.find(i => i.id == item)) {
      //       selectZP.push(this.ZPLBQList.find(i => i.id == item))
      //     }
      //   })
      //   console.log(selectZP, '已经配置的中频滤波器可读不可写')
      //   selectZP.forEach(item => {
      //     this.changeCheckS(item, 1)//界面展示已经配置的中频滤波器
      //   })
      //   let bzbhValue = 3//本振编号的数值
      //   this.formInline.localOscillator = bzbhValue
      //   this.changeLocalOscillator(bzbhValue)//联动中心频点
      //   let selectedArr = [72, 73, 74, 75, 76, 77, 78, 79, 80]

      //   this.SZLBQList.forEach(i => {
      //     console.log(i, '数字滤波器的item')
      //     if (selectedArr.indexOf(Number(i.id)) !== -1) {
      //       //不是可选数组里的都禁用
      //       i.disabled = false
      //     } else {
      //       i.disabled = true
      //     }
      //   })
      // }
    },

    ballConfig(val) {
      let act = this.$refs.pool.subData.filter((i) => i.check == true)
      let str = ''
      act.forEach((i, index) => {
        str += i.id.toString(16).padStart(4, 0).toUpperCase()
      })
      if (val == '4-信道') {
        this.formBall.packageGridValue = str.toUpperCase()
        httpAction(this.url.addnmcPackageGridValue, this.formBall, 'post').then((res) => {
          this.visibleAdd = false
          if (res.success) {
            this.$message.success(res.message)
          } else {
            this.$message.warning(res.message)
          }
        })
      }
    },
    Turns(str, type) {
      if (type == 16) {
        //8位二进制数转2位十六进制数
        let d = []
        let c = str
        for (let i = 0; i < c.length; i += 4) {
          d.push(c.slice(i, i + 4))
        }
        let items = ''
        d.forEach((item) => {
          // 把num当做2进制的值 转换为10进制
          item = JSON.parse(JSON.stringify(parseInt(item, 2).toString(16)))
          items += item
        })
        return items.toUpperCase()
      }

      if (type == 2) {
        //十六进制转8位二进制数
        let d = []
        let c = str
        for (let i = 0; i < c.length; i += 1) {
          d.push(c.slice(i, i + 1))
        }
        let items = ''
        d.forEach((item) => {
          item = JSON.parse(JSON.stringify(parseInt(item, 16).toString(2))).padStart(4, 0)
          items += item
        })
        return items
      }
    },
    handleSend() {
      let selectZP = []
      this.ZPLBQList.forEach(i => {
        if (!i.disabled && i.check) {
          selectZP.push(i.id)
        }
      })
      let selectSZ = []
      this.SZLBQList.forEach(i => {
        if (!i.disabled && i.check) {
          selectSZ.push(i.id)
        }
      })
      this.form1.digitalFilters = selectSZ.map(String);
      this.form1.disturbedDigitalFilters = this.form1.disturbedDigitalFilters.map(String)
      this.form1.intermediateFrequencyFilters = selectZP.map(String)
      if (!selectSZ.length) {
        this.$message.error('未选择信道号')
      }
      if (!selectZP.length) {
        this.$message.error('未选择中频滤波器')
      }
      httpAction(this.url.uplinkFrequencySwitchDecision, this.form1, 'post').then(res => {
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)
        }
      })
    },

    handleConfig() {
      this.$refs.configModal.showModal({}, 'ball')
    },


    changeCarCounts(val) {
      this.multipleTreeData = []
      let children = []
      for (let i = 1; i <= 32; i++) {
        children.push({
          id: `${i}-1`,
          value: `导弹${i}`,
          label: `导弹${i}`,
        })
      }
      for (let i = 1; i <= val; i++) {
        this.multipleTreeData.push({
          id: i,
          value: `指挥车${i}`,
          label: `指挥车${i}`,
          children: [...children],
        })
      }
    },
    callback(key) {
      this.tabActiveKey = key
      this.ac.forEach((i, index) => {
        if (i.active == this.tabActiveKey) {
          this.ac.splice(index, 1)
        }
      })
    },
    filter(val) {
      if (this.checkList.indexOf(val) != -1) {
        return true
      } else {
        return false
      }
    },
  },
}
</script>
<style lang="less">
.ant-input-group-wrapper .ant-input-wrapper .ant-input-group-addon {
  color: #fff;
}
.taskAllocation {
  .ant-checkbox-group {
    // height: 300px;
    // line-height: 0.9;
    .ant-checkbox-wrapper {
      margin: 0;
    }
    .ant-col {
      width: auto;
      margin: 0;
    }
  }
}
.tabs .ant-row {
  width: 600px;
  .ant-checkbox-inner {
    width: 40px !important;
    height: 40px !important;
    text-align: center;
    &::after {
      width: 7px;
      height: 14px;
      left: 35%;
    }
  }
}
.ant-checkbox-inner {
  /* background-color: red !important; */
  border-color: #6e6e6e !important;
}
.ant-form-item-control {
  line-height: 0 !important;
}
.on,
.off,
.dis {
  color: #fff;
  margin-right: 8px;
  margin-left: 8px;
  font-size: 20px;
  line-height: 40px;
}
.on::after {
  content: '';
  display: inline-block;
  height: 16px;
  width: 16px;
  line-height: 40px;
  // border: 0.1px solid #7e7c7c;
  margin-left: 15px;
  background: #36f73f;
}
.off::after {
  content: '';
  display: inline-block;
  height: 16px;
  width: 16px;
  line-height: 20px;
  // border: 0.1px solid #7e7c7c;
  margin-left: 15px;
  background: #f51616;
}
.dis::after {
  content: '';
  display: inline-block;
  height: 16px;
  width: 16px;
  line-height: 20px;
  // border: 0.1px solid #7e7c7c;
  margin-left: 15px;
  background: linear-gradient(
    45deg,
    rgba(117, 117, 117, 0.6) 0,
    rgba(117, 117, 117, 0.6) 10%,
    rgba(42, 44, 43, 1) 10%,
    rgba(42, 44, 43, 1) 20%,
    rgba(117, 117, 117, 0.6) 20%,
    rgba(117, 117, 117, 0.6) 30%,
    rgba(42, 44, 43, 1) 30%,
    rgba(42, 44, 43, 1) 40%,
    rgba(117, 117, 117, 0.6) 40%,
    rgba(117, 117, 117, 0.6) 50%,
    rgba(42, 44, 43, 1) 50%,
    rgba(42, 44, 43, 1) 60%,
    rgba(117, 117, 117, 0.6) 60%,
    rgba(117, 117, 117, 0.6) 70%,
    rgba(42, 44, 43, 1) 70%,
    rgba(42, 44, 43, 1) 80%,
    rgba(117, 117, 117, 0.6) 80%,
    rgba(117, 117, 117, 0.6) 90%,
    rgba(42, 44, 43, 1) 90%,
    rgba(42, 44, 43, 1) 100%
  );
}
.ZPLBQList {
  width: 100%;
  display: flex;
  // flex: 1;
  .ZPLBQBox {
    flex: auto;
    user-select: none;
    .offcheck,
    .oncheck,
    .disabledStyle {
      line-height: 60px;
    }
  }
}
.SZLBQList {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  .SZLBQBox {
    width: 40px;
    height: 40px;
    line-height: 40px;
    user-select: none;
    // border: 1px solid #ad1616;
    .offcheck,
    .oncheck,
    .disabledStyle {
      line-height: 40px;
    }
  }
}
.offcheck,
.oncheck,
.disabledStyle {
  width: 100%;
  height: 100%;
  border: 1px solid #7e7979;
  margin: -1px 0 0 -1px;
  text-align: center;
}
.offcheck {
  color: #000;
  background: #f51616;
}
.disabledStyle {
  color: #898383;
  // background: #868686;
  background: linear-gradient(
    45deg,
    rgba(117, 117, 117, 0.6) 0,
    rgba(117, 117, 117, 0.6) 10%,
    rgba(42, 44, 43, 1) 10%,
    rgba(42, 44, 43, 1) 20%,
    rgba(117, 117, 117, 0.6) 20%,
    rgba(117, 117, 117, 0.6) 30%,
    rgba(42, 44, 43, 1) 30%,
    rgba(42, 44, 43, 1) 40%,
    rgba(117, 117, 117, 0.6) 40%,
    rgba(117, 117, 117, 0.6) 50%,
    rgba(42, 44, 43, 1) 50%,
    rgba(42, 44, 43, 1) 60%,
    rgba(117, 117, 117, 0.6) 60%,
    rgba(117, 117, 117, 0.6) 70%,
    rgba(42, 44, 43, 1) 70%,
    rgba(42, 44, 43, 1) 80%,
    rgba(117, 117, 117, 0.6) 80%,
    rgba(117, 117, 117, 0.6) 90%,
    rgba(42, 44, 43, 1) 90%,
    rgba(42, 44, 43, 1) 100%
  );
}
.oncheck {
  color: #000;
  background: #36f73f;
}

.has-error .ant-input,
.has-error .ant-input:hover {
  background-color: transparent;
  border: 1px solid #17dcff;
}
</style>
